package com.yanqu.road.server.manger.config;

import com.yanqu.road.entity.config.winery.WineryConfig;
import com.yanqu.road.logic.bussiness.config.WineryConfigBusiness;
import com.yanqu.road.server.TempMgr;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class WineryConfigMgr extends TempMgr {

    private static final Map<Integer,  WineryConfig> wineryConfigMap = new ConcurrentHashMap<>();

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean reloadConfig() throws Exception {
        List<WineryConfig> wineryConfigList = WineryConfigBusiness.getWineryConfigList();
        for (WineryConfig wineryConfig : wineryConfigList) {

            wineryConfigMap.put(wineryConfig.getId(), wineryConfig);
        }
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean stop() {
        return false;
    }

    public static Map<Integer,WineryConfig>  getWineryConfigMap() {
        return wineryConfigMap;
    }


    public static WineryConfig getWineryConfig(int id) {
        if (null == WineryConfigMgr.wineryConfigMap.get(id)) {
            return null;
        }
        return WineryConfigMgr.wineryConfigMap.get(id);
    }
}
